 <template>
  <el-container>
    <el-main>
      <!-- <div class='tip' style="margin-top: 20px;">
          <strong>特别注意：</strong>为确保调账对象正确，防止误操作，请务必输入账户名和手机号后，再开始调账。
      </div>
      <section class="form_contianer0" style="margin-top: 20px">     
          <div class="manage_tip">
          </div>
          <el-form :model="accountInfo" ref="accountInfo">
              <el-form-item prop="userName" class="adminGetUserInfo">
                  <el-input v-model="accountInfo.userName" placeholder="用户名" style="width: 200px;" clearable></el-input>
              </el-form-item>
              <el-form-item prop="tel" class="adminGetUserInfo">
                  <el-input v-model="accountInfo.tel" placeholder="手机号码" style="width: 200px;" clearable></el-input>
              </el-form-item>
          </el-form>
      </section> -->
      <section class="form_contianer" style="margin-top: 50px">     
          <div class="manage_tip">
              <p>该用户增加金币数量(单位:元)</p>
          </div>
          <el-form :model="formDataIn" ref="formDataIn">
              <el-form-item prop="orderAmount" class="adminAdjust">
                  <el-input v-model="formDataIn.orderAmount" placeholder="金额" style="width: 200px;" clearable></el-input>
              </el-form-item>

              <el-form-item>
                  <el-button type="primary" @click="adminAdjustToInWithUserInfo(formDataIn)" class="submit_btn">立即增加金币</el-button>
              </el-form-item>
          </el-form>

      </section>

      <section class="form_contianer2" style="margin-bottom: 50px">
          <div class="manage_tip">
              <p>该用户减少金币数量(单位:元)</p>
          </div>
          <el-form :model="formDataOut" ref="formDataOut">
              <el-form-item prop="orderAmount" class="adminAdjust">
                  <el-input v-model="formDataOut.orderAmount" placeholder="金额" style="width: 200px;" clearable></el-input>
              </el-form-item>

              <el-form-item>
                  <el-button type="primary" @click="adminAdjustToOutWithUserInfo(formDataOut)" class="submit_btn">立即减少金币</el-button>
              </el-form-item>
          </el-form>

      </section>
    </el-main>
  </el-container>
</template>

<script>
    import {adminGetUserInfo, adminAdjust, adminAdjustConfirm} from '@/api/admin'

    export default {
      data () {
        return {
          formDataIn: {
            orderCode: '200111', orderAmount: 0, userId: 0
          },
          formDataOut: {
            orderCode: '200112', orderAmount: 0, userId: 0
          },
          adjustConfirmDto: {
            id: 1,
            status: 'ENABLE'
          },
          accountInfo: {
            userName: '',
            tel: ''
          },
          userInfo: {
            userId: 0
          }


        }
      },
      mounted () {
        this.initData()
      },
      methods: {
        async initData () {
        },

        async adminAdjustToIN (formDataIn) {
          let formDataInCopy = Object.assign({}, this.formDataIn)
          formDataInCopy.userId = this.userInfo.userId
          formDataInCopy.orderAmount = Math.abs((this.formDataIn.orderAmount *100 ).toFixed(0))
          
          let result = await adminAdjust(formDataInCopy)
          if (result.status === 200 && result.data.code === 200) {
            let data = result.data
            this.adjustConfirmDto.id = data.data.id
            
            this.adminAdjustConfirmClick()
          } else {
          }
        },
        async adminAdjustToOut (formDataOut) {
          let formDataOutCopy = Object.assign({}, this.formDataOut)
          formDataOutCopy.userId = this.userInfo.userId
          formDataOutCopy.orderAmount = Math.abs((this.formDataOut.orderAmount *100 ).toFixed(0))

        //   this.formDataOut.userId = this.userInfo.userId
        //   this.formDataOut.orderAmount = this.formDataOut.orderAmount *100 
          let result = await adminAdjust(formDataOutCopy)
          if (result.status === 200 && result.data.code === 200) {
            let data = result.data
    
            this.adjustConfirmDto.id = data.data.id
            this.adminAdjustConfirmClick()
          } else {
    
          }
        },

        async adminAdjustConfirmClick (adjustConfirmDto) {
          let result = await adminAdjustConfirm(this.adjustConfirmDto)
          if (result.status === 200 && result.data.code === 200) {
            this.$message({
              type: 'success',
              message: '调账成功'
            })
          } else {
    
          }
        },
        async adminGetUserInfoClick (accountInfo) {
          let result = await adminGetUserInfo(this.accountInfo)
          if (result.status === 200 && result.data.code === 200) {
            let data = result.data
            this.userInfo.userId = data.data[0].id
            this.$message({
              type: 'success',
              message: '用户匹配成功，请开始输入金额..'
            })
          } else {
            this.$message({
              type: 'error',
              message: '未匹配到用户'
            })
          }
        },
        // 直接用了以下全流程的方法
        async adminAdjustToInWithUserInfo (formDataIn) {
          let result = await adminGetUserInfo(this.accountInfo)
          if (result.status === 200 && result.data.code === 200) {
            let data = result.data
            this.userInfo.userId = data.data[0].id
            this.adminAdjustToIN(this.formDataIn)
            
          } else {
            this.$message({
              type: 'error',
              message: '未匹配到用户'
            })
          }
        },
        async adminAdjustToOutWithUserInfo (formDataOut) {
          let result = await adminGetUserInfo(this.accountInfo)
          if (result.status === 200 && result.data.code === 200) {
            let data = result.data
            this.userInfo.userId = data.data[0].id
            this.adminAdjustToOut(this.formDataOut)
          } else {
            this.$message({
              type: 'error',
              message: '未匹配到用户'
            })
          }
        }

      }
    }
</script>

<style lang="less" scoped>
    @import '../../style/mixin';
    .label-title{
        font-weight: bold;
        font-size: 24px;
        color: #ff633b;
        margin: 30px;
    }
    .manage_tip {
      margin-bottom: 10px;
    }
    .introduct{
        width: 900px;
        text-align: center;
        margin: auto;
    }
    .tip {
        font-size: 12px;
    }
    .tip strong {
        color: red;
        font-weight: bold;
    }
    // .el-button {
    //   width: 200px;
    //   margin: auto;
    //   display: block;
    // }
    .el-table .info-row {
        background: #c9e5f5;
    }

    .el-table .positive-row {
        background: #e2f0e4;
    }
</style>

 